const mongoose = require('mongoose')

mongoose.connect(
    'mongodb://localhost:27017/school-system',
    {
        useCreateIndex: true,
        useNewUrlParser: true,
        useUnifiedTopology: true
    }
)
//定义表结构--用户表
const UserSchema = new mongoose.Schema({
    username: { type: String, unique: true },
    password: {
        type: String,
        set(val) {
            return require("bcrypt").hashSync(val, 10)  //调用bcrypt进行散列，级数为10
        }
    }
})

// 构建用户模型
const User = new mongoose.model('User', UserSchema)


// User.db.dropCollection('users')
// 导出用户模型
module.exports = { User }